﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
       
    }
    protected void username_TextChanged(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string Time = DateTime.Now.ToString();
        string ip = Request.UserHostAddress.ToString();
        Sqlselete ss = new Sqlselete();
        SqlInsert sl = new SqlInsert();
        if (username.Text.Trim() == "")
        {
            Response.Write("<script>alert('请输入帐号!!')</script>");
        }
        else if (password.Text.Trim() == "")
        {
            Response.Write("<script>alert('请输入密码!!')</script>");

        }
        else
        {
            string UserName = this.username.Text.Trim();
            string Password = password.Text.Trim();

            if (ss.Login(UserName, Password) == false)
            {
                string State = "登录失败";

                sl.InsertLoginInfo(UserName, Time, ip, State);
                Response.Write("<script>alert('帐号或密码错误！！')</script>");
            }
            else
            {
                string State = "登录成功";
                sl.InsertLoginInfo(UserName, Time, ip, State);
                Session["UserName"] = UserName;

                // int Purview = ss.Log in(UserName, Password);
                //  Session["Purview"] = Purview;
                //    Response.Write("<script>window.open('Default.aspx');window.close();</script>");
                
                Response.Redirect("Default.aspx");

                //string tt = " qminoa = window.open('Default.aspx" + "'"
                //  + ",'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,top=0;left=0,width=900,height=700');";
                //Response.Write("<script language=javascript>");
                //Response.Write(tt);
                //Response.Write("qminoa.moveTo(0,0);");
                //Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);");
                //Response.Write("window.opener=null;");
                //Response.Write("window.close();");
                //Response.Write("</script>");
            }
        }
    } 
}
